classdef DiffNoInv < Cell
    
    properties
    end
    
    methods
        function this = DiffNoInv(poles,g)
            this.Name = 'Non-inverting Differentiator';
            this.Poles = poles;
            this.Zeros = 0;
            this.Gain = g;
            wp = abs(poles);
            this.calcCell(wp,g);
            this.ImagePath = 'Stages Schematics/Diff_No_Inv.png';
        end
        
        function calcCell(obj,wp,g)
            if wp < 100
                caux = 2.2e-6;
            else
                if wp < 1000
                    caux = 220e-9;
                else
                    if wp < 10000
                        caux = 22e-9;
                    else
                        if wp < 100000
                            caux = 2.2e-9;
                        else
                            if wp < 1000000;
                                caux = 220e-12;
                            else
                                caux = 100e-12;
                            end
                        end
                    end
                end
            end
            resists(1) = 1/(wp*caux);
            resists(3) = 10e3;
            resists(2) = (g-1)*resists(3);
            obj.Resists = resists;
            obj.Caps = caux;
            sens(1) = -1;
            sens(2) = 0;
            sens(3) = 0;
            sens(4) = -1;
            obj.Senswp = sens;
            sens(1) = 0;
            sens(2) = resists(2)/(resists(2)+resists(3));
            sens(3) = -sens(2);
            sens(4) = 0;
            obj.SensG = sens;
            
            obj.error = ~obj.validateComponents(obj.Resists,obj.Caps);
        end
        
        function componentChange(obj,component,value)
            obj.error = 0;
            caps = obj.Caps;
            resists = obj.Resists;
            switch component
                case 1
                    obj.Resists(1) = value;
                    obj.Caps = 1/(abs(obj.Poles)*value);
                case 2
                    obj.Resists(2) = value;
                    obj.Resists(3) = obj.Resists(2)/(obj.Gain-1);
                    obj.SensG(2) = obj.Resists(2)/(obj.Resists(2)+obj.Resists(3));
                    obj.SensG(3) = -obj.SensG(2);
                case 3
                    obj.Resists(3) = value;
                    obj.Resists(2) = (obj.Gain-1)*value;
                    obj.SensG(2) = obj.Resists(2)/(obj.Resists(2)+obj.Resists(3));
                    obj.SensG(3) = -objG.Sens(2);
                case 4
                    obj.Caps = value;
                    obj.Resists(1) = 1/(abs(obj.Poles)*value);
            end
            status = obj.validateComponents(obj.Resists,obj.Caps);
            if ~status
                obj.Resists = resists;
                obj.Caps = caps;
                obj.error = 1;
            end
        end
    end
end